//
//  CustomTabBarViewController.m
//  ViewAnimation
//
//  Created by Billy on 15/5/21.
//  Copyright (c) 2015年 seven. All rights reserved.
//

#import "CustomTabBarViewController.h"

#import "HomePageViewController.h"
#import "OrderViewController.h"
#import "PriceQueryTableViewController.h"
#import "ShoppingCartViewController.h"
#import "UserCenterViewController.h"

@interface CustomTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation CustomTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIUtil colorWithHexString:@"#ff9b2f"] }
                                             forState:UIControlStateSelected];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.translucent = NO;
    [self setDelegate:self];

    [self subControllersCreation];
}


#pragma mark - SubControllerCreation

- (void) subControllersCreation {
    
    // 首页
    
    HomePageViewController *homeVC = [[HomePageViewController alloc] init];
    
    [self setSubController:homeVC withTitle:@"首页"
                                                                andDefautImageName:@"homeItem"
                                                                andSelectedImageName:@"homeItemSelected"];
    
    //询价

    PriceQueryTableViewController *queryVC = [[PriceQueryTableViewController alloc] init];
    
    [self setSubController:queryVC withTitle:@"询价"
                                                                andDefautImageName:@"priceQueryItem"
                                                                andSelectedImageName:@"priceQueryItemSelected"];
    queryVC.ifTab = YES;
    queryVC.ifPriceQuery = YES;
    
    // 下单
    
    OrderViewController *orderVC = [[OrderViewController alloc] init];

    [self setSubController:orderVC withTitle:@"大货下单"
                                                                 andDefautImageName:@"orderItem"
                                                                 andSelectedImageName:@"orderItemSelected"];
    orderVC.ifTab = YES;
    
    // 购物车
    
    ShoppingCartViewController *cartVC = [[ShoppingCartViewController alloc] init];
    
    [self setSubController:cartVC withTitle:@"购物车"
                                                                 andDefautImageName:@"shoppingCartItem"
                                                                 andSelectedImageName:@"shoppingCartItemSelected"];
    
    // 我
    
    UserCenterViewController *userVC = [[UserCenterViewController alloc] init];
    
    [self setSubController:userVC withTitle:@"我"
                                                                 andDefautImageName:@"meItem"
                                                                 andSelectedImageName:@"meItemSelected"];
    
}



- (void) setSubController:(UIViewController *) subViewController withTitle:(NSString *) title
                                            andDefautImageName:(NSString *) defaultImageName
                                            andSelectedImageName:(NSString *) selectionImageName{
    
    [subViewController.tabBarItem setTitle:title];
    
    
    [subViewController.tabBarItem setImage:[UIImage imageNamed:defaultImageName]];
    
    [subViewController.tabBarItem setSelectedImage:[[UIImage imageNamed:selectionImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:subViewController];
    
    [self addChildViewController:nav];
}

#pragma mark - TabBar delegate

//用来定位用户选择的item选择
- (void)tabBarController:(UITabBarController *)tabBarController   didSelectViewController:(UIViewController *)viewController {
}

@end
